<?
/**
 * This file is part of XNAT light.
 *
 * XNAT light is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * XNAT light is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XNAT light.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace NRG\Framework\Exceptions;

/**
 * Authentication exception
 *
 * @package NRG\Framework\Exceptions
 */
class AuthException extends BaseException
{
    /**
     * No username
     *
     * @var int
     */
    const NO_USERNAME = 1;

    /**
     * No password
     *
     * @var int
     */
    const NO_PASSWORD = 2;

    /**
     * Authentication failed
     * 
     * @var int
     */
    const AUTH_FAILED = 3;

    /**
     * Administrator only
     *
     * @var int
     */
    const ADMIN_ONLY = 4;

    /**
     * Exception type
     *
     * @var const
     */
    protected $_type;

    /**
     * Constructor
     *
     * @param type int
     */
    public function __construct($type)
    {
	$this->_type = $type;
	$this->createMessage();
    }

    /**
     * Get exception type
     *
     * @return const
     */
    public function getType()
    {
	return $this->_type;
    }

    /**
     * Get exception message
     *
     * @return string
     */
    public function createMessage()
    {
	switch($this->_type)
	{
	    case self::NO_USERNAME:
		$this->message = "no username supplied";
		break;
	    case self::NO_PASSWORD:
		$this->message = "no password supplied";
		break;
	    case self::AUTH_FAILED:
		$this->message = "authentication failed";
		break;
	    case self::ADMIN_ONLY:
		$this->message = "administratory only";
		break;
	    default:
		$this->message = "unknown authentication exception";
		break;
	}

	return $this->message;
    }

    /**
     * To string
     *
     * @return string
     */
    public function __toString()
    {
	return $this->getMessage();
    }
}
